<script type="text/javascript">
	function ScoreQueryCtrl(CtrlUtil, $http, $scope, modalService, $element) {
		var ctrl = this
		CtrlUtil.build(this, ':root/score/queryScore', $scope.ctrl)
		this.add = function () {
			var content = $element.find('[template]>[add]').clone()
			modalService.confirm({
				title: '添加成绩',
				content: content,
				search: {
					enable: true
				},
				result: {
					stuInfo: {}
				},
				ctrl: ctrl
			}).then(function (r) {
				$http.post(':root/score/addScore', r).success(function (R) {
					if (R) {
						modalService.succ('添加成功', 1500)
						ctrl.query()
					} else {
						modalService.error('添加失败', 1500)
					}
				})
			})
		}
		CtrlUtil.loadDepartment(ctrl)
		this.edit = function (item) {
			var content = $element.find('[template]>[add]').clone()
			modalService.confirm({
				title: '修改成绩',
				content: content,
				search: {
					enable: false,
					stuInfo: item.stuInfo
				},
				result: item,
				ctrl: ctrl
			}).then(function (r) {
				$http.post(':root/score/addScore', r).success(function (R) {
					if (R) {
						modalService.succ('修改成功', 1500)
						ctrl.query()
					} else {
						modalService.error('修改失败', 1500)
					}
				})
			})
		}
		this.searchStudent = function (name, target) {
			$http.post(':root/trainee/queryStudents', {
				name: name,
				pageSize: 9
			}).success(function (r) {
				target = target || ctrl
				target.students = r
			})
		}

		this.socreChange = function (result) {
			result.zj = (parseFloat(result.xzt || 0) + parseFloat(result.zgt || 0))
			result.khjg = (result.zj > 85 ? '优秀' : (result.zj > 75 ? '良好' : (result.zj > 60 ? '合格' : '不通过')))
		}
		this.import = function () {
			var content = $element.find('[import]').clone()
			var modal = modalService.show({
				title: '成绩导入',
				content: content,
				upload: function () {
					content.find('form').ajaxForm().ajaxSubmit({
						url: require.toUrl('root/score/importScore'),
						success: function (r) {
							if (r == '') {
								modalService.succ('导入成功', 1500)
							} else {
								modalService.succ('导入失败：' + r, 1500)
							}
							modal.close()
						},
						error: function () {
							modalService.error('导入失败', 1500)
						}
					});
				},
				term: ctrl.termQueryParam,
				supCtrl: $scope.ctrl
			}, {
					backdrop: false
				})
		}
	}

</script>
<div ng-controller="ScoreQueryCtrl as subCtrl" ng-init="ctrl.subCtrl=subCtrl;ctrl.query()">
	<div class="">
		<button type="button" class="btn btn-cys btn-sm" ng-click="subCtrl.add()">
			<span class="glyphicon glyphicon-plus"></span>
			添加
		</button>
		<button type="button" class="btn btn-cys btn-sm" ng-click="subCtrl.import()">
			<span class="glyphicon glyphicon-import"></span>
			成绩导入
		</button>
		<button type="button" class="btn btn-cys btn-sm" ng-click="export(ctrl,'root/score/exportScore')">
			<span class="glyphicon glyphicon-export"></span>
			导出
		</button>
		<div ng-if="subCtrl" ng-init="ctrl=subCtrl" class="pull-right" ng-include="':root/components/page.html'"></div>
	</div>
	<!-- operation area END -->
	<!-- data grid area -->
	<div style="padding-top: 10px;" ng-if="subCtrl">
		<table class="table table-bordered table-hover table-striped" ng-init="ctrl=subCtrl">
			<tr>
				<th>
					<input ng-change="ctrl.checkAll(ctrl.$checkAll)" ng-model="ctrl.$checkAll" type="checkbox" />
				</th>
				<th>姓名</th>
				<th>性别</th>
				<th>学号</th>
				<th>院系</th>
				<!-- <th>专业</th> -->
				<th>所属班级</th>
				<th>考核结果</th>
				<th>操作</th>
			</tr>
			<tr ng-repeat="item in ctrl.entities.content">
				<td>
					<input ng-model="item.$checked" type="checkbox" />
				</td>
				<td>{{item.stuInfo.user.name}}</td>
				<td>{{item.stuInfo.sexString}}</td>
				<td>{{item.stuInfo.user.uid}}</td>
				<td>{{ctrl.departmentMap[item.stuInfo.user.department].name}}</td>
				<!-- <td>{{item.stuInfo.student.major.name}}</td> -->
				<td>{{item.stuInfo.classInfo.bjName}}</td>
				<td>{{item.khjg}}</td>
				<td>
					<a href="javascript:;" class="remove-underline" ng-click="ctrl.edit(item)">编辑</a>
				</td>
			</tr>
		</table>
		<p>
			共有记录：
			<span>{{ctrl.entities.totalElements}}</span> 条
		</p>
	</div>
	<div class="hidden" ng-non-bindable template>
		<div add>
			<form class="form-horizontal" single-student>
				<div class="form-group" ng-show="search.enable">
					<label class="col-md-2 control-label">学生</label>
					<div class="col-md-10 open">
						<input type="text" ng-change="ctrl.searchStudent(search.name,search)" ng-model="search.name" class="form-control" placeholder="按姓名/学号模糊搜索">
						<ul class="dropdown-menu" ng-show="search.students.content.length>0">
							<li ng-repeat="t in search.students.content">
								<a href="javascript:;" ng-click="search.stuInfo=t;result.stuInfo.id=t.id;search.students=null;">({{t.user.uid}}){{t.user.name}}-{{t.term.name+t.term.trainType.name}}</a>
							</li>
						</ul>
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">期次</label>
					<div class="col-md-10">
						<input type="text" class="form-control" disabled="disabled" title="{{search.stuInfo.term.name+search.stuInfo.term.trainType.name}}" value="{{search.stuInfo.term.name+search.stuInfo.term.trainType.name}}">
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">姓名</label>
					<div class="col-md-4">
						<input type="text" ng-model="search.stuInfo.user.name" class="form-control" disabled="disabled">
					</div>
					<label class="col-md-2 control-label">性别</label>
					<div class="col-md-4">
						<input type="text" class="form-control" ng-model="search.stuInfo.sexString" disabled="disabled">
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-md-2 control-label">学号/工号</label>
					<div class="col-md-4">
						<input type="text" class="form-control" disabled="disabled" value="{{search.stuInfo.user.uid}}">
					</div>
					<label class="col-md-2 control-label">年级</label>
					<div class="col-md-4">
						<input type="text" class="form-control" ng-model="search.stuInfo.user.grade" disabled="disabled" value="2015">
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">院系</label>
					<data entity="Department" auto-load="true" after-refresh="Dep=data[0]">
						<filter field="id" value="search.stuInfo.user.department"></filter>
					</data>
					<div class="col-md-4">
						<input type="text" class="form-control" disabled="disabled" ng-model="Dep.name">
					</div>
					<label class="col-md-2 control-label">职务</label>
					<div class="col-md-4">
						<input class="form-control" disabled="disabled" ng-model="search.stuInfo.zw">
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">联系电话</label>
					<div class="col-md-4">
						<input type="text" disabled="disabled" ng-model="search.stuInfo.phone" class="form-control">
					</div>
					<label class="col-md-2 control-label">QQ</label>
					<div class="col-md-4">
						<input type="text" disabled="disabled" ng-model="search.stuInfo.qq" class="form-control">
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">班级</label>
					<div class="col-md-4">
						<input class="form-control" disabled="disabled" ng-model="search.stuInfo.classInfo.bjName">
					</div>
					<label class="col-md-2 control-label">校区</label>
					<div class="col-md-4">
						<span class="form-control" disabled="disabled" ng-bind="search.stuInfo.xq"></span>
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">备注</label>
					<div class="col-md-10">
						<input type="text" disabled="disabled" class="form-control" ng-model="search.stuInfo.bz">
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">考核结果</label>
					<div class="col-md-10">
						<select class="form-control" ng-model="result.khjg">
							<option ng-value=""></option>
							<option ng-value="'优秀'">优秀</option>
							<option ng-value="'良好'">良好</option>
							<option ng-value="'合格'">合格</option>
							<option ng-value="'不通过'">不通过</option>
						</select>
					</div>
				</div>
			</form>
		</div>
		<div import class="col-md-10 col-md-offset-1">
			<form class="form-horizontal" enctype="multipart/form-data" method="post">
				<div class="form-group">
					<div class="col-md-12 ">
						<select name="term" class="form-control" chosen ng-value="term">
							<option value="">期次</option>
							<option value="{{m.id}}" ng-selected="$index==0" ng-repeat="m in supCtrl.terms">{{(m.name+'-第'+m.qs+'期')}}</option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<div class="col-md-12">
						<input class="form-control" id="fileImport" name="file" type="file" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-md-12">
						<a type="submit" ng-click="upload()" class="btn btn-success">导入</a>
						<a class="btn btn-link btn-sm" href="asset/excel/studenScoreSample.xls">
							<span class="glyphicon glyphicon-arrow-down"></span>
							导入模板下载
						</a>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>